/*
package com.t309.tzy.controller;
import com.alibaba.fastjson.JSON;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/provider")
public class SupplierController {

    @Resource
    private SupplierService providerService;
    */
/**
     * 跳转供货商查询页面
     * @return
     *//*

    @RequestMapping("/toProviderList")
    public String toProviderList(Model model,HttpSession session){
        if (session.getAttribute(Constants.USER_SESSION) == null) {
            return "redirect:/user/login";
        } else if (model.getAttribute("providerList") == null) {
            return "redirect:/provider/getProviderList";
        }
        return "/supplier/list";
    }

    @GetMapping("/getProviderList")
    public String getProviderList(Model model,String querySupCode,String querySupName,Integer pageIndex){
        PageSupport pageSupport = new PageSupport();
        pageSupport.setPageSize(10);
        if (pageIndex != null) {
            pageSupport.setCurrentPageNo(pageIndex);
        } else {
            pageSupport.setCurrentPageNo(1);
        }
        pageSupport.setTotalCount(providerService.getProviderCount(querySupCode, querySupName));
        pageSupport.setPagelimit((pageSupport.getCurrentPageNo() - 1) * 10);
        List<Provider> list = providerService.getProviderList(querySupCode, querySupName, pageSupport);
        model.addAttribute("pageSupport", pageSupport);
        model.addAttribute("providerList", list);
        return "/supplier/list";
    }


    @RequestMapping("/toProviderAdd")
    public String toProviderAdd(HttpSession session){
        if (session.getAttribute("user") == null){
            return "redirect:/user/login";
        }
        return "/supplier/add";
    }

    @PostMapping("/providerAdd")
    public String providerAdd(HttpServletRequest request,HttpSession session, String supCode,
                              String supName, String supContact,
                              String supPhone, String supAddress,
                              String supFax, String supDesc, @RequestParam("attachs") MultipartFile[] attachs) throws IOException {
        String companyLicPic = null;
        String orgCodePic = null;
        String errorInfo = null;
        boolean flag = true;
        String path = request.getSession().getServletContext().getRealPath("statics" + File.separator + "uploadfiles");
        System.out.println("文件储存路径" + path);
        for (int i = 0; i < attachs.length; i++){
            MultipartFile attach = attachs[i];
            if (!attach.isEmpty()){
                if (i == 0){
                    errorInfo = "uploadFileError";
                }else if (i == 1){
                    errorInfo = "uploadWpError";
                }
                String oldFileName = attach.getOriginalFilename();  //原文件名
                System.out.println("原文件名" + oldFileName);
                String prefix = FilenameUtils.getExtension(oldFileName); //原文件后缀
                System.out.println("原文件后缀" + prefix);
                int filesize = 500000;
                if (attach.getSize() > filesize){
                    request.setAttribute(errorInfo,"上传大小不得超过500kb");
                    flag = false;
                }else if (prefix.equalsIgnoreCase("JPG")
                        || prefix.equalsIgnoreCase("jpg")
                        || prefix.equalsIgnoreCase("png")
                        || prefix.equalsIgnoreCase("jpeg")
                        || prefix.equalsIgnoreCase("pneg")){
                    String fileName = System.currentTimeMillis() + RandomUtils.nextInt(1000000) + "_Personal." + prefix;
                    File targetFile = new File(path);
                    if (!targetFile.exists()){
                        targetFile.mkdirs();
                    }
                    attach.transferTo(new File(targetFile, fileName));
                    if (i == 0){
                        companyLicPic = File.separator + "statics" + File.separator + "uploadfiles" + File.separator + fileName;
                    }else if (i == 1){
                        orgCodePic = File.separator + "statics" + File.separator + "uploadfiles" + File.separator + fileName;
                    }
                    System.out.println("companyLicPic:" + companyLicPic);
                    System.out.println("workPicPath:" + orgCodePic);
                } else {
                    request.setAttribute(errorInfo, "上传图片格式不正确");
                    flag = false;
                }
            }
        }
        if (flag) {
            User Admin = (User) session.getAttribute("user");
            Provider provider = new Provider();
            provider.setProCode(supCode);
            provider.setProName(supName);
            provider.setProContact(supContact);
            provider.setProPhone(supPhone);
            provider.setProAddress(supAddress);
            provider.setProFax(supFax);
            provider.setDesc(supDesc);
            provider.setModifyBy(Admin.getId().longValue());
            Date date = new Date();
            provider.setModifyDate(date);
            provider.setCreatedBy(Admin.getId().longValue());
            provider.setCreationDate(date);
            provider.setCompanyLicPic(companyLicPic);
            provider.setOrgCodePic(orgCodePic);
            providerService.addProvider(provider);
            System.out.println("添加成功");
        }
        return "/supplier/add";
    }

    @ResponseBody
    @GetMapping("/delete")
    public Object deleteProvider(Long id){
        HashMap<String, Object> resultMap = new HashMap<>();
            Provider provider = providerService.getProviderById(id);
            if (null != provider){
                Boolean flag = providerService.deleteProvider(id);
                if (flag){
                    System.out.println("删除成功");
                    resultMap.put("delResult","true");
                }else{
                    System.out.println("删除失败");
                    resultMap.put("delResult","false");
                }
            }else {
                System.out.println("用户不存在");
                resultMap.put("deResult","notexist");
            }
        return JSON.toJSONString(resultMap);
    }
}
*/
